package com.kfpanda.search.action.searchmg;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.kfpanda.search.action.BaseAction;
import com.kfpanda.search.biz.searchmg.FileBIZ;

@Repository
@Controller
@Scope("prototype")
public class FileAction extends BaseAction {
	
	@Resource
	private FileBIZ fileBIZ;
	
	@RequestMapping("/file/detail.htm")
	public String indexAdd(ModelMap model, @RequestParam String filePath){
		filePath = StringUtils.isBlank(filePath) ? "" : filePath;
		int beginIndex = filePath.lastIndexOf("/") < 0 ? filePath.lastIndexOf("\\") : filePath.lastIndexOf("/");
		beginIndex = beginIndex < 0 ? 0 : beginIndex;
		int endIndex = filePath.indexOf(".");
		endIndex = endIndex < 0 ? filePath.length() : endIndex;
		model.put("fileName", filePath.substring(beginIndex, endIndex));
		model.put("contents", fileBIZ.fileDetail(filePath));
		return "file/detail";
	}
}
